package library.frames;

import library.download.Download;
import library.frames.model.DownloadTableModel;

public class DownloadsFrame extends javax.swing.JFrame {

    private static DownloadsFrame instance = new DownloadsFrame();
    private DownloadTableModel model = new DownloadTableModel();

    public static DownloadsFrame getInstance() {
        return instance;
    }

    private DownloadsFrame() {
        initComponents();
        this.downloadsList.setModel(model);
    }

    public void addNewDownload(Download d) {
        this.model.addDownload(d);
        updateStatus();
    }

    public void updateStatus() {
        this.setVisible(true);
        this.downloadsList.updateUI();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        downloadsList = new javax.swing.JTable();

        setTitle("Загрузки");

        downloadsList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Книга", "Состояние"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        downloadsList.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(downloadsList);
        downloadsList.getColumnModel().getColumn(0).setResizable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 534, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable downloadsList;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
